Add 'heading_true_degrees' to return degrees from 0->360 instead of -180->180.
authorrobertl <robertl>
Tue, 1 Aug 2006 15:55:02 +0000 (15:55 +0000)
committerrobertl <robertl>
Tue, 1 Aug 2006 15:55:02 +0000 (15:55 +0000)
grtcirc.c
grtcirc.h
internal_styles.c
route.c
trackfilter.c
wbt-200.c

index 18d8db12db606f315a27b7b42f344e99e2feb545..16769e654b4595c05f20236d6076b01ce4ad23cb 100644 (file)
--- a/grtcirc.c
+++ b/grtcirc.c
@@ -92,7 +92,9 @@ double gcdist( double lat1, double lon1, double lat2, double lon2 )
        return 2.0 * res;
 }
 
-/* This value is the heading you'd leave point 1 at to arrive at point 2. */
+/* This value is the heading you'd leave point 1 at to arrive at point 2. 
+ * Inputs and outputs are in radians.
+ */
 double heading( double lat1, double lon1, double lat2, double lon2 ) {
   double v1, v2;
   v1 = sin(lon1 - lon2) * cos(lat2);
@@ -103,7 +105,15 @@ double heading( double lat1, double lon1, double lat2, double lon2 ) {
   return atan2(v1, v2);
 }
 
-       
+/* As above, but outputs is in degrees from 0 - 359.  Inputs are still radians. */
+double heading_true_degrees( double lat1, double lon1, double lat2, double lon2 ) 
+{
+  double h = 360.0 - DEG(heading(lat1, lon1, lat2, lon2));
+  if (h > 360) h -= 360;
+
+  return h;
+}
+
  
 double linedist(double lat1, double lon1,
                double lat2, double lon2,
index c50ee4591169373ca8ab560bb54996658800d990..c47e77dd4ccc592c013bd73e2ec0f9a06aa49e22 100644 (file)
--- a/grtcirc.h
+++ b/grtcirc.h
@@ -24,6 +24,7 @@
 
 double gcdist( double lat1, double lon1, double lat2, double lon2 );
 double heading( double lat1, double lon1, double lat2, double lon2 );
+double heading_true_degrees( double lat1, double lon1, double lat2, double lon2 );
 
 double linedist(double lat1, double lon1,
                double lat2, double lon2,
@@ -37,8 +38,10 @@ void linepart(double lat1, double lon1,
                double frac,
                double *reslat, double *reslon ); 
 
-
+/* Degrees to radians */
 #define DEG(x) ((x)*180.0/M_PI)
+
+/* Radians to degrees */
 #define RAD(x) ((x)*M_PI/180.0)
 
 #endif
index 807024c5717d41416e46eacbe7eb10133fb68e0c..e302db82a7431ebef225db4ffeedb2c56a864ae3 100644 (file)
@@ -795,6 +795,40 @@ static char saplus[] =
 "IFIELD  URL, \"\", \"%s\"                   # URL\n"
 "IFIELD  IGNORE, \"\", \"\"                  # Holder for Geocache Type\n"
 
+;
+static char sportsim[] = 
+"# gpsbabel XCSV style file\n"
+"#\n"
+"# Format: Sportsim track files\n"
+"# Author: Olaf Klein\n"
+"#   Date: 07/05/2006\n"
+"#\n"
+"DESCRIPTION   Sportsim track files (part of zipped .ssz files) \n"
+"EXTENSION     txt\n"
+
+"#\n"
+"# FILE LAYOUT DEFINITIIONS:\n"
+"#\n"
+"FIELD_DELIMITER               SEMICOLON\n"
+"RECORD_DELIMITER      CRNEWLINE\n"
+"BADCHARS              TAB\n"
+
+"#\n"
+"# FILE HEADER\n"
+"#\n"
+"PROLOGUE      SportsimVersion:01\n"
+"PROLOGUE      \\#Sportsim TrackFile\n"
+
+"#\n"
+"# INDIVIDUAL DATA FIELDS:\n"
+"#\n"
+"IFIELD        INDEX, \"\", \"%05d\"\n"
+"IFIELD        CONSTANT, \"0\", \"%s\"\n"
+"IFIELD        LAT_DECIMAL, \"\", \"%f\"\n"
+"IFIELD        LON_DECIMAL, \"\", \"%f\"\n"
+"IFIELD        ALT_FEET, \"\", \"%.f\"\n"
+"IFIELD        TIMET_TIME, \"\", \"%ld\"\n"
+"IFIELD        CONSTANT, \";\", \"%s\"\n"
 ;
 static char tabsep[] = 
 "# gpsbabel XCSV style file\n"
@@ -958,8 +992,8 @@ static char xmapwpt[] =
 "IFIELD        IGNORE, \"\", \"%-.31s\"\n"
 "IFIELD        DESCRIPTION, \"\", \"%-.78s\"\n"
 ;
-style_vecs_t style_list[] = {{ "xmapwpt", xmapwpt } , { "xmap", xmap } , { "xmap2006", xmap2006 } , { "tabsep", tabsep } , { "saplus", saplus } , { "s_and_t", s_and_t } , { "openoffice", openoffice } , { "nima", nima } , { "mxf", mxf } , { "mapconverter", mapconverter } , { "kwf2", kwf2 } , { "ktf2", ktf2 } , { "gpsman", gpsman } , { "gpsdrivetrack", gpsdrivetrack } , { "gpsdrive", gpsdrive } , { "geonet", geonet } , { "garmin_poi", garmin_poi } , { "garmin301", garmin301 } , { "fugawi", fugawi } , { "dna", dna } , { "custom", custom } , { "cup", cup } , { "csv", csv } , { "cambridge", cambridge } , { "arc", arc } ,  {0,0}};
-size_t nstyles = 25;
+style_vecs_t style_list[] = {{ "xmapwpt", xmapwpt } , { "xmap", xmap } , { "xmap2006", xmap2006 } , { "tabsep", tabsep } , { "sportsim", sportsim } , { "saplus", saplus } , { "s_and_t", s_and_t } , { "openoffice", openoffice } , { "nima", nima } , { "mxf", mxf } , { "mapconverter", mapconverter } , { "kwf2", kwf2 } , { "ktf2", ktf2 } , { "gpsman", gpsman } , { "gpsdrivetrack", gpsdrivetrack } , { "gpsdrive", gpsdrive } , { "geonet", geonet } , { "garmin_poi", garmin_poi } , { "garmin301", garmin301 } , { "fugawi", fugawi } , { "dna", dna } , { "custom", custom } , { "cup", cup } , { "csv", csv } , { "cambridge", cambridge } , { "arc", arc } ,  {0,0}};
+size_t nstyles = 26;
 #else /* CSVFMTS_ENABLED */
 style_vecs_t style_list[] = {{0,0}};
 size_t nstyles = 0;
diff --git a/route.c b/route.c
index d72b0b469510f4c51cee4247d013bb6adb8a8a35..6760c40369b53b02f942e322b47951a9f381ec89 100644 (file)
--- a/route.c
+++ b/route.c
@@ -517,8 +517,8 @@ void track_recompute(const route_head *trk, computed_trkdata **trkdatap)
                tlon = RAD(this->longitude);
                plat = RAD(prev->latitude);
                plon = RAD(prev->longitude);
-               this->course = DEG(heading(plat, plon,
-                       tlat, tlon));
+               this->course = heading_true_degrees(plat, plon,
+                       tlat, tlon);
                dist = radtometers(gcdist(plat, plon, tlat, tlon));
 
                /* 
index 84ba3da4176e6a606dafa432370c7b26426da5b3..f904db4960eabf0afeeaedfa9b40fc99175e8adc 100644 (file)
@@ -654,9 +654,9 @@ trackfilter_synth(void)
                }
                else {
                        if ( opt_course ) {
-                               wpt->course = DEG(heading( RAD(oldlat), 
+                               wpt->course = heading_true_degrees( RAD(oldlat), 
                                        RAD(oldlon),RAD(wpt->latitude), 
-                                       RAD(wpt->longitude) ));
+                                       RAD(wpt->longitude) );
                        }
                        if ( opt_speed ) {
                                if ( oldtime != wpt->creation_time ) {
index 7922f9230f49c960fc4aa3182d2a16e51693263d..40550644785af4e97ad78e06f7f69ef881a30f21 100644 (file)
--- a/wbt-200.c
+++ b/wbt-200.c
@@ -221,8 +221,8 @@ static void data_chunk(struct read_state *st, const void *buf) {
         speed               = rtm / dtim;
         
         wpt->speed          = speed;
-               wpt->course         = DEG(heading(RAD(st->plat), RAD(st->plon),
-                                             RAD(lat), RAD(lon)));
+               wpt->course         = heading_true_degrees(RAD(st->plat), RAD(st->plon),
+                                             RAD(lat), RAD(lon));
                wpt->pdop               = 0;
                wpt->fix                    = fix_unknown;